/*
 * 代号：凤凰
 * http://www.jphenix.org
 * 2017年1月26日
 * V4.0
 */
package com.jphenix.sdk.ftp.impl;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import com.jphenix.standard.docs.ClassInfo;

/**
 * TelnetOutputStream类
 * 
 * 取自JDK1.8中的 sun.net.TelnetOutputStream 反编译结果
 * 
 * @author MBG
 * 2024年3月28日
 */
@ClassInfo({"2024-03-29 10:22","TelnetOutputStream类"})
public class TelnetOutputStream extends BufferedOutputStream {
  boolean stickyCRLF = false;
  
  boolean seenCR = false;
  
  public boolean binaryMode = false;
  
  public TelnetOutputStream(OutputStream paramOutputStream, boolean paramBoolean) {
    super(paramOutputStream);
    this.binaryMode = paramBoolean;
  }
  
  public void setStickyCRLF(boolean paramBoolean) {
    this.stickyCRLF = paramBoolean;
  }
  
  public void write(int paramInt) throws IOException {
    if (this.binaryMode) {
      super.write(paramInt);
      return;
    } 
    if (this.seenCR) {
      if (paramInt != 10)
        super.write(0); 
      super.write(paramInt);
      if (paramInt != 13)
        this.seenCR = false; 
    } else {
      if (paramInt == 10) {
        super.write(13);
        super.write(10);
        return;
      } 
      if (paramInt == 13)
        if (this.stickyCRLF) {
          this.seenCR = true;
        } else {
          super.write(13);
          paramInt = 0;
        }  
      super.write(paramInt);
    } 
  }
  
  public void write(byte[] paramArrayOfbyte, int paramInt1, int paramInt2) throws IOException {
    if (this.binaryMode) {
      super.write(paramArrayOfbyte, paramInt1, paramInt2);
      return;
    } 
    while (--paramInt2 >= 0)
      write(paramArrayOfbyte[paramInt1++]); 
  }
}
